#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m], b[m][n];
  for (auto& line: a) {
    for (auto& x: line) {
      cin >> x;
    }
  }
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      // (0, 0) -> (0, n-1)
      // (0, m-1) -> (m-1, n-1)
      // (n-1, 0) -> (0, 0)
      b[j][n-1-i] = a[i][j];
    }
  }
  for (auto& line: b) {
    for (auto& x: line) {
      cout << x << ' ';
    }
    cout << endl;
  }
}